C++ string中find() ,rfind() 等函数 用法总结及示例 您所在的位置:网站首页 string rfind返回值 C++ string中find() ,rfind() 等函数 用法总结及示例

C++ string中find() ,rfind() 等函数 用法总结及示例

2023-05-16 09:07| 来源: 网络整理| 查看: 265

string中 find()的应用  (rfind()

原型如下:

(1)size_t find (const string& str, size_t pos = 0) const;  //查找对象--string类对象

(2)size_t find (const char* s, size_t pos = 0) const; //查找对象--字符串

(3)size_t find (const char* s, size_t pos, size_t n) const;  //查找对象--字符串的前n个字符

(4)size_t find (char c, size_t pos = 0) const;  //查找对象--字符

结果:找到 -- 返回 第一个字符的索引

     没找到--返回   string::npos

示例:

#include // std::cout #include // std::string int main () { std::string str ("There are two needles in this haystack with needles."); std::string str2 ("needle"); // different member versions of find in the same order as above: std::size_t found = str.find(str2); if (found!=std::string::npos) std::cout


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有